package o;

import android.content.Context;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.json.JSONObject;

public class bab extends azz {
    public byte[] ˏ(Context context, String str) {
        return ˋ(context, str, null);
    }

    public byte[] ˋ(Context context, String str, Map<String, String> map) {
        byte[] bArr = null;
        try {
            bArr = ˊ(context, str, map).getBytes("UTF-8");
        } catch (Exception e) {
            azh.ˏ.ˏ("PostWapParamCreator", "get post bytes error");
        }
        if (bArr == null) {
            return new byte[0];
        }
        return bArr;
    }

    public String ˊ(Context context, String str, Map<String, String> map) {
        return ॱ(ˏ(context, str, map));
    }

    public String ˎ(Context context, String str, Map<String, String> map) {
        Map ˏ = ˏ(context, str, map);
        try {
            JSONObject jSONObject = new JSONObject();
            for (Entry entry : ˏ.entrySet()) {
                jSONObject.put((String) entry.getKey(), entry.getValue());
            }
            return jSONObject.toString();
        } catch (Exception e) {
            azh.ˏ.ˏ("PostWapParamCreator", "createPostDataJoson error");
            return "";
        }
    }

    protected Map<String, String> ˏ(Context context, String str, Map<String, String> map) {
        Map<String, String> ˎ = ˎ(context, str);
        if (map != null) {
            Set<Entry> entrySet = map.entrySet();
            if (entrySet != null && entrySet.size() > 0) {
                for (Entry entry : entrySet) {
                    if (!ˎ.containsKey(entry.getKey())) {
                        ˎ.put(entry.getKey(), entry.getValue());
                    }
                }
            }
        }
        return ˎ;
    }

    public String ॱ(Map<String, String> map) {
        if (map == null) {
            return "";
        }
        String[] strArr = (String[]) map.keySet().toArray(new String[map.keySet().size()]);
        int length = strArr.length;
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < length; i++) {
            String str = strArr[i];
            stringBuilder.append(str).append('=').append((String) map.get(str));
            if (i != length - 1) {
                stringBuilder.append('&');
            }
        }
        return stringBuilder.toString();
    }

    public Map<String, String> ˎ(Context context, String str) {
        Map<String, String> hashMap = new HashMap();
        if (bbd.ॱ(str) != azp.INTERNAL) {
            return hashMap;
        }
        ˏ(context, hashMap);
        hashMap.put("AG_token", ॱ());
        Object obj = null;
        if (UserSession.getInstance().isLoginSuccessful()) {
            obj = UserSession.getInstance().getDeviceId();
        }
        if (dof.ॱ(obj)) {
            obj = ˊ();
        }
        hashMap.put("AG_deviceId", obj);
        hashMap.put("AG_oldDeviceIdType", UserSession.getInstance().getDeviceType());
        hashMap.put("AG_deviceIdType", ˏ());
        return hashMap;
    }

    private String ॱ() {
        UserSession instance = UserSession.getInstance();
        String str = "";
        if (!instance.isLoginSuccessful() || cgy.ˎ(instance.getServiceToken())) {
            return str;
        }
        return instance.getServiceToken();
    }

    private String ˏ() {
        return String.valueOf(new bjy(ContentManager.getInstant().getContext()).ॱ().ˏ);
    }

    private String ˊ() {
        return new bjy(ContentManager.getInstant().getContext()).ॱ().ˎ;
    }
}
